<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
  <base target="_self"/>
    <link rel="stylesheet" type="text/css" href="<%=path %>/web/style/layout.css" />
    <script type="text/javascript" src="<%=path %>/jqGrid/js/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="<%=path %>/jslib/jquery.validate.min.js"></script>
    <script type='text/javascript' src="<%=request.getContextPath() %>/jslib/My97DatePicker/WdatePicker.js" defer="defer"></script>
    <script type='text/javascript' src="<%=request.getContextPath() %>/jslib/jquery.form.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath() %>/jslib/additional-methods.js"></script>
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/jslib/jquery-easyui-1.4.1/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/jslib/jquery-easyui-1.4.1/themes/icon.css">
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/jslib/jquery-easyui-1.4.1/demo.css">
	<script type="text/javascript" src="<%=request.getContextPath() %>/jslib/jquery-easyui-1.4.1/jquery.easyui.min.js"></script>
    <c:if test="${requestScope.message!=null}">
		<script type="text/javascript">
 	 		     alert('<c:out value="${requestScope.message}"></c:out>');
 	 		     window.close();
 		</script>
	</c:if>
	
    <script type="text/javascript">
    var api = frameElement.api, W = api.opener;
    var stateValue="";
    $().ready(function(){
            
			var options = {
		  	    url:'<%=request.getContextPath() %>/eqAction!saveData.action',
		  	     beforeSubmit: function() {
		   				return checking();
		    			},
		  	    dataType:'json',
		  	    success: function(data) {
		  	      if(data.result=='success'){
					alert("添加成功");
					api.close();
					W.refreshIt();
		  	      }
		  	    }};
		$('#saveBtn').click(function(){
			    	$('#pageFrom').ajaxSubmit(options);
	 	            return false;
    	 });
    	$('#closeBtn').click(function(){
    		api.close();
		});
		
	});
	
   	function checking(){
   		var flag = true;
		var equName = $.trim($("#equName").val());
		var equNo = $.trim($("#equNo").val());
		var equGuge = $.trim($("#equGuge").val());
		var equCNo = $.trim($("#equCNo").val());
		var equHtNo = $.trim($("#equHtNo").val());
		var equGjDate = $.trim($("#equGjDate").val());
		var equYjsynx = $.trim($("#equYjsynx").val());
		var equYjsysj = $.trim($("#equYjsysj").val());
		var equHblx = $.trim($("#equHblx").val());
		var equHtjg = $.trim($("#equHtjg").val());
		var equShuilv = $.trim($("#equShuilv").val());
		var equHuilv = $.trim($("#equHuilv").val());
		var equYzhi = $.trim($("#equYzhi").val());
		var equYzw = $.trim($("#equYzw").val());
		var equJzw = $.trim($("#equJzw").val());
		var equZjw = $.trim($("#equZjw").val());
		if(equName ==null || equName == "" ){
			alert("设备名称不能为空！");
			$("#equName").focus();
    		return false;
		}
		if(equNo ==null || equNo == "" ){
			alert("设备编号不能为空！");
			$("#equNo").focus();
    		return false;
		}
		if(equGuge ==null || equGuge == "" ){
			alert("规格型号不能为空！");
			$("#equGuge").focus();
    		return false;
		}
		if(equCNo ==null || equCNo == "" ){
			alert("出厂编号不能为空！");
			$("#equCNo").focus();
    		return false;
		}
		if(equHtNo ==null || equHtNo == "" ){
			alert("合同编号不能为空！");
			$("#equHtNo").focus();
    		return false;
		}
		if(equGjDate ==null || equGjDate == "" ){
			alert("购进日期（转固日期）不能为空！");
			$("#equGjDate").focus();
    		return false;
		}
		if(equYjsynx ==null || equYjsynx == "" ){
			alert("预计使用年限（年）不能为空！");
			$("#equYjsynx").focus();
    		return false;
		}else if(!checkNum(equYjsynx)){
			alert("请输入数字！");
			$("#equYjsynx").focus();
    		return false;
		}
		if(equYjsysj ==null || equYjsysj == "" ){
			alert("已经使用时间（月）不能为空！");
			$("#equYjsysj").focus();
    		return false;
		}
		if(equHblx ==null || equHblx == "" ){
			alert("货币类型不能为空！");
			$("#equHblx").focus();
    		return false;
		}
		if(equHtjg ==null || equHtjg == "" ){
			alert("合同价格不能为空！");
			$("#equHtjg").focus();
    		return false;
		}else if(!checkNum(equHtjg)){
			alert("请输入数字！");
			$("#equHtjg").focus();
    		return false;
		}
		if(equShuilv ==null || equShuilv == "" ){
			alert("税率(%)不能为空！");
			$("#equShuilv").focus();
    		return false;
		}else if(!checkNum(equShuilv)){
			alert("请输入数字！");
			$("#equShuilv").focus();
    		return false;
		}
		if(equHuilv ==null || equHuilv == "" ){
			alert("汇率不能为空！");
			$("#equHuilv").focus();
    		return false;
		}else if(!checkNum(equHuilv)){
			alert("请输入数字！");
			$("#equHuilv").focus();
    		return false;
		}
		if(equYzhi ==null || equYzhi == "" ){
			alert("原值（元）不能为空！");
			$("#equYzhi").focus();
    		return false;
		}else if(!checkNum(equYzhi)){
			alert("请输入数字！");
			$("#equYzhi").focus();
    		return false;
		}
		if(equYzw ==null || equYzw == "" ){
			alert("原值（万元）不能为空！");
			$("#equYzw").focus();
    		return false;
		}else if(!checkNum(equYzw)){
			alert("请输入数字！");
			$("#equYzw").focus();
    		return false;
		}
		if(equJzw ==null || equJzw == "" ){
			alert("净值（万元）不能为空！");
			$("#equJzw").focus();
    		return false;
		}else if(!checkNum(equJzw)){
			alert("请输入数字！");
			$("#equJzw").focus();
    		return false;
		}
		if(equZjw ==null || equZjw == "" ){
			alert("折旧（万元）不能为空！");
			$("#equZjw").focus();
    		return false;
		}else if(!checkNum(equZjw)){
			alert("请输入数字！");
			$("#equZjw").focus();
    		return false;
		}
	}
	 
	function checkExp(inputData){ 
		var regEx = new RegExp(/^(([^\^\.<>%&',:;=?$"'#@!~\]\[{}【】￥（）！·‘’”“。，、？：；—|\/\\/`\|])*)$/);
		var result = inputData.match(regEx);
		if (result == null) {
			return false;
		}
		return true;
	}
	function checkNum(inputData){
		var sNumber;
	    sNumber=Number(inputData);
	    if (isNaN(inputData)){
	       return false;
	     }
	    return true;
	}
	function countlen1(textarea){
	       var elem = event.relatedTarget || event.srcElement || event.target ||event.currentTarget;    
	        if(event.keyCode!=8)
			{
			  if (textarea.value.length> 249){
			        alert("最多为250个字符,字符输入超出限制!");
			        textarea.value=textarea.value.substring(0,249);
			    }
			    return true;
	 	    }
	}
		
	  //选择部门
	function selectdept(id)
	{
		var datas = window.showModalDialog("<%=request.getContextPath() %>/resource/choose/choose_organizationIndex.jsp?temp="+Math.round(Math.random()*10000),'',"dialogWidth=900px;dialogHeight=550px");
		if(typeof(datas) == 'undefined'){
		}else{
			var json1 = eval('(' + datas + ')');
			 document.getElementById("dept_"+id).value = json1.ORG_NAME;
			 document.getElementById(id).value = json1.ORG_ID;
		}
	}
	

	function changevalue(id){
	 	var flag = "0";
	 	if(id == 1){
	 		var fileValue = document.getElementById("file1").value;
	 		var a=fileValue.lastIndexOf("\\");
	 		var filequName = fileValue.substring(a+1);
			document.getElementById("gongyingshangzizhi").value=filequName;
			flag = "1";
		}else if(id == 2){
		    var fileValue = document.getElementById("file2").value;
	 		var a=fileValue.lastIndexOf("\\");
	 		var filequName = fileValue.substring(a+1);
			document.getElementById("gongyingshangpingjia").value=filequName;
			flag = "2";
		}
		document.getElementById("flag").value=flag;
	}
	
	//已经使用时间（月）
	function changeDate(){
		var myDate = new Date();
		var year = myDate.getFullYear();  
		var month = myDate.getMonth();
	    month = month+1;
		//var fullDate = year+"-"+month;
		//var date1 = fullDate.split('-');
		var date1 = parseInt(year) * 12 + parseInt(month);
		var zgDate = $('#equGjDate').val();
		date2 = zgDate.split('-');
		date2 = parseInt(date2[0]) * 12 + parseInt(date2[1]);
		var months  = Math.abs(date1 - date2);
		document.getElementById("equYjsysj").value = months ;
	}
	
		//原值（万元）、净值（万元）d、折旧（万元）小数点后保留6位有效数字。
	function changePrice(){
		var equShuilv = $('#equShuilv').val();
		var equHtjg = $('#equHtjg').val();
		var equHuilv = $('#equHuilv').val();
		var equYzhi = $('#equYzhi').val();
		var equYzw = $('#equYzw').val();
		var equJzw = $('#equJzw').val(); 
		var equYjsynx = $('#equYjsynx').val();
		var equYjsysj = $('#equYjsysj').val();
		
		if(equYjsynx ==null || equYjsynx == "" ){
			alert("预计使用年限（年）不能为空！");
			$("#equYjsynx").focus();
    		return false;
		}else if(!checkNum(equYjsynx)){
			alert("请输入数字！");
			$("#equYjsynx").focus();
    		return false;
		}
		if(equShuilv== null || equShuilv ==""){
			alert("税率(%)不能为空！");
			$("#equShuilv").focus();
    		return false;
		}else if(!checkNum(equShuilv)){
			alert("请输入数字！");
			$("#equShuilv").focus();
    		return false;
		}
		if(equHuilv ==null || equHuilv == "" ){
			alert("汇率不能为空！");
			$("#equHuilv").focus();
    		return false;
		}else if(!checkNum(equHuilv)){
			alert("请输入数字！");
			$("#equHuilv").focus();
    		return false;
		}
		if(equHtjg ==null || equHtjg == "" ){
			alert("合同价格不能为空！");
			$("#equHtjg").focus();
    		return false;
		}else if(!checkNum(equHtjg)){
			alert("请输入数字！");
			$("#equHtjg").focus();
    		return false;
		}
		//原值=汇率*合同价格/（1+税率） 小数点保留两位有效数字 
		document.getElementById("equYzhi").value = parseFloat((equHuilv*equHtjg)/(1+parseFloat(equShuilv))).toFixed(2);
		//原值（万）=原值/10000    6位
		equYzhi = $('#equYzhi').val();
		document.getElementById("equYzw").value = parseFloat(equYzhi/10000).toFixed(6);
		//折旧=原值（万元）*月折旧率*已经使用时间 （月折旧率=0.95/预计使用年限/12） 6位
		var yzjl = 0.95/(equYjsynx/12);
		equYzw = $('#equYzw').val();
		document.getElementById("equZjw").value = parseFloat(equYzw*yzjl*equYjsysj).toFixed(6);
		//净值  =原值（万元）-折旧（万元）   6位
		equYzw = $('#equYzw').val();
		equZjw = $('#equZjw').val();
		document.getElementById("equJzw").value = parseFloat(equYzw - equZjw).toFixed(6);
	}
	
	  //选择设备台账
	function selectsbtz(id){
		var datas = window.showModalDialog("<%=request.getContextPath() %>/view/choose_equipment_tz.jsp?temp="+Math.round(Math.random()*10000),'',"dialogWidth=900px;dialogHeight=550px");
		if(typeof(datas) == 'undefined'){
		}else{
			var json1 = eval('(' + datas + ')');
			 document.getElementById("equName").value = json1.EQUIPMENT_NAME;
			 document.getElementById("equId").value = json1.id;
			 document.getElementById("equNo").value = json1.EQUIPMENT_NO;
			 document.getElementById("equGuge").value = json1.EQUIPMENT_GGXH;
			 document.getElementById("equCNo").value = json1.EQUIPMENT_CCBH;
			 getHetong(json1.id);
		}
	}
	
	function getHetong(id){
		jQuery.post("eqAction!getHetong.action?equMainId="+id,
				{"type" : "notall"},
				callHetong,
				"json");
	 }
	 function callHetong(json){
		 $("#equHtNo").empty();
			var html = ''; //<option value="">--请选	择--</option>
			  $('#equHtNo').append(html);
			if(json!=''){
			$.each(json,function(entryindex,entry){
				html = '<option value="'+entry['id']+'">' + entry['name'] + '</option>';
				$('#equHtNo').append(html);
			});
		}
	 }
	
   </script>
 	<style type="text/css">
 		body{
 			background:#ffffff; background-image:url(images/);
 		}
   		html{
		    overflow-x: hidden;
			overflow-y: hidden;
		}  	
		.formTableNew textarea{border: 1px solid #999;padding: 5px;width: 760px;-moz-border-radius: 3px;border-radius: 3px;margin-bottom: 5px;color: #666;background: url(../images/input_bg.gif) repeat-x top;}
   </style>
  </head>
  
  <body>
<form id="pageFrom" action="" enctype="multipart/form-data" method="post">
        <input type="hidden" id="flag" name="flag" />
  		<table width="100%" border="0" align="center" cellpadding="5" cellspacing="5" class="formTableNew">
  		<input id="eid" type="hidden" name="tequipment.id" value=""/>
  			<tr>
  			  <td align="right">设备名称：</td>
  			  <td align="left">
  			    <input  type="text" readonly  id="equName" maxlength="50" name="tequipment.equName" style="border: 1px solid #999;padding: 5px;width: 250px;height:25px;"  value="" />
  			  	<input  type="hidden"  id="equId" maxlength="50" name="tequipment.equMainId" style="border: 1px solid #999;padding: 5px;width: 250px;height:25px;"  value="" />
  			  	<img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			  	<img src="/gwm/web/images/form_icon_1.gif" style="cursor:hand; vertical-align: middle;" onclick="selectsbtz(equId)" />
  			  </td>
  			  <td align="right">设备编号：</td>
  			  <td align="left">
  			    <input  type="text" readonly id="equNo" maxlength="50" name="tequipment.equNo" style="border: 1px solid #999;padding: 5px;width: 250px;height:25px;"  value="" />
  			  	<img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			  </td>
  			</tr>
  			<tr>
  			  <td align="right">规格型号：</td>
  			  <td align="left">
  			    <input  type="text" readonly  id="equGuge" maxlength="50" name="tequipment.equGuge" style="border: 1px solid #999;padding: 5px;width: 250px;height:25px;"  value="" />
  			  	<img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			  </td>
  			  <td align="right">出厂编号：</td>
  			  <td align="left">
  			    <input  type="text"  readonly id="equCNo" maxlength="50" name="tequipment.equCNo" style="border: 1px solid #999;padding: 5px;width: 250px;height:25px;"  value="" />
  			  	<img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			  </td>
  			</tr>
  			<tr>
  			  <td align="right">合同编号：</td>
  			  <td align="left">
  			  	<select   name="tequipment.equHtNo" id="equHtNo" class='fselect' class='easyui-validatebox'  style="border: 1px solid #999;padding: 5px;width: 250px;height:40px;" onkeydown="if(event.keyCode==8)return false;"></select>
  			  	<img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			  </td>
  			  <td align="right">购进日期（转固日期）：</td>
  			  <td align="left">
  			    <input  type="text"  id="equGjDate"  name="tequipment.equGjDate" onClick="WdatePicker({maxDate:new Date()})" onChange="changeDate()" style="border: 1px solid #999;padding: 5px;width: 250px;height:25px;"  value="" />
  			  	<img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			  </td>
  			</tr>
  			<tr>
  			  <td align="right">预计使用年限（年）：</td>
  			  <td align="left">
  			    <input  type="text"  id="equYjsynx" maxlength="3" onChange="changePrice()" name="tequipment.equYjsynx" style="border: 1px solid #999;padding: 5px;width: 250px;height:25px;"  value="" />
  			  	<img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			  </td>
  			  <td align="right">已经使用时间（月）：</td>
  			  <td align="left">
  			  	 <input  type="text"  id="equYjsysj" readonly  maxlength="50" name="tequipment.equYjsysj" style="border: 1px solid #999;padding: 5px;width: 250px;height:25px;"  value="" />
  			  	<img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			  </td>
  			</tr>
  			<tr>
  			  <td align="right">货币类型：</td>
  			  <td align="left">
  			  	<select id="equHblx" class='fselect' name="tequipment.equHblx" class='easyui-validatebox' style="border: 1px solid #999;padding: 5px;width:250px;height:25px;" >
 			      <option value="人民币">人民币</option>
			 	  <option value="美元">美元</option>
			 	  <option value="欧元">欧元</option>
			 	  <option value="日元">日元</option>
			 	  <option value="英镑">英镑</option>
			 	  <option value="港元">港元</option>
			 	  <option value="加元">加元</option>
			 	  <option value="卢布">卢布</option>
 			    </select>
  			  	<img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			  </td>
  			  <td align="right">合同价格：</td>
  			  <td align="left">
  			    <input  type="text"  id="equHtjg" maxlength="11" name="tequipment.equHtjg" onChange="changePrice()" style="border: 1px solid #999;padding: 5px;width: 250px;height:25px;"  value="" />
  			  	<img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			  </td>
  			</tr>
  			<tr>
  			  <td align="right">税率(%)：</td>
  			  <td align="left">
  			    <input  type="text"  id="equShuilv" maxlength="10" name="tequipment.equShuilv" onChange="changePrice()" style="border: 1px solid #999;padding: 5px;width: 250px;height:25px;"  value="" />
  			  	<img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			  </td>
  			  <td align="right">汇率：</td>
  			  <td align="left">
  			    <input  type="text"  id="equHuilv" maxlength="10" name="tequipment.equHuilv" onChange="changePrice()" style="border: 1px solid #999;padding: 5px;width: 250px;height:25px;"  value="" />
  			  	<img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			  </td>
  			</tr>
  			<tr>
  			  <td align="right">原值（元）：</td>
  			  <td align="left">
  			    <input  type="text"  id="equYzhi" maxlength="50" name="tequipment.equYzhi" style="border: 1px solid #999;padding: 5px;width: 250px;height:25px;"  value="" />
  			  	<img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			  </td>
  			  <td align="right">原值（万元）：</td>
  			  <td align="left">
  			    <input  type="text"  id="equYzw" maxlength="50" name="tequipment.equYzw" style="border: 1px solid #999;padding: 5px;width: 250px;height:25px;"  value="" />
  			  	<img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			  </td>
  			</tr>
  			<tr>
  			  <td align="right">净值（万元）：</td>
  			  <td align="left">
  			    <input  type="text"  id="equJzw" maxlength="50" name="tequipment.equJzw" style="border: 1px solid #999;padding: 5px;width: 250px;height:25px;"  value="" />
  			  	<img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			  </td>
  			  <td align="right">折旧（万元）：</td>
  			  <td align="left">
  			    <input  type="text"  id="equZjw" maxlength="50" name="tequipment.equZjw" style="border: 1px solid #999;padding: 5px;width: 250px;height:25px;"  value="" />
  			  	<img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			  </td>
  			</tr>
 			<tr>
		    <td align="right"  >备注：</td>
		    <td colspan="3">
		    	<div class="div">
					<textarea rows="5" cols="100" id="remark" name="tequipment.remark" onkeydown="countlen1(this);" style="width: 726px;"></textarea>
				</div>	
		    </td>
		  </tr>
		</table>
		<table width="100%" border="0" align="center" class="formTableNew">
		  <tr>
			<td align="center">
		    	<input id="saveBtn" type="button" value="提 交" class="form_bt_orange" />
		    	<input type="button" id="closeBtn" value="取 消" class="form_bt_grey" />
		    </td>
		  </tr>
		</table>
	<!--表单结束-->
	</form>
  </body>
</html>
